package com.cn.xiaonuo.slbfinances.slbagents.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.DateUtils;
import com.cn.xiaonuo.common.utils.StringUtils;
import com.cn.xiaonuo.dbs.core.annotation.DataSource;
import com.cn.xiaonuo.slbfinances.slbagents.mapper.PvTradeMapper;
import com.cn.xiaonuo.slbfinances.slbagents.service.IPvTradeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class PvTradeServiceImpl extends ServiceImpl<PvTradeMapper, String> implements IPvTradeService {

    @Resource
    private PvTradeMapper pvTradeMapper;

    //搜了宝-->匀贸兑酒记录
    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage financeExchangeList(Integer pageNum, Integer pageSize, String statTime, String endTime, String accounts, String userId, String productId) {
        BusinessMessage message = new BusinessMessage();
        if (null == pageNum || pageNum <= 1) {
            pageNum = 1;
        }
        if (null == pageSize || pageSize <= 1) {
            pageSize = 10;
        }
        // 设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        if (StringUtils.isNotBlank(statTime)) {
            statTime = DateUtils.stampToDate(statTime);
            endTime = DateUtils.stampToDate(endTime);
        }
        List<Map<String, Object>> maps = pvTradeMapper.financeExchangeList(statTime, endTime, accounts, userId, productId);
        PageInfo<Map<String, Object>> map = new PageInfo<>(maps);
        message.setData(map);
        message.setSuccess(true);
        return message;
    }
    @Override
    //和平村记录查询--寄存销售推广打款记录
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage hitMoneylog(String startTime, String endTime, Integer pageNum, Integer pageSize) {
        BusinessMessage message = new BusinessMessage();
        if (null == pageNum || pageNum <= 1) {
            pageNum = 1;
        }
        if (null == pageSize || pageSize <= 1) {
            pageSize = 10;
        }
        // 设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        if (StringUtils.isNotBlank(startTime)) {
            startTime = DateUtils.stampToDate(startTime);
            endTime = DateUtils.stampToDate(endTime);
        }
        List<Map<String, Object>> maps = pvTradeMapper.hitMoneylog(startTime, endTime);
        PageInfo<Map<String, Object>> map = new PageInfo<>(maps);
        message.setData(map);
        message.setSuccess(true);
        return message;
    }
}
